#include "operation_factory.h"

Operation *OperationFactory::CreateOperation(std::string operate)
{
    if (operate.length() != 1) {
        std::cout << "Invalid operator. Please input +, -, * or /." << std::endl;
        exit(-1);
    }
    char oper = operate[0];
    Operation *op = nullptr;
    switch(oper) {
        case '+':
            op = new OperationAdd();
            break;
        case '-':
            op = new OperationSub();
            break;
        case '*':
            op = new OperationMul();
            break;
        case '/':
            op = new OperationDiv();
            break;
        default:
            std::cout << "Invalid operator. Please input +, -, * or /." << std::endl;
            exit(-1);
    }
    return op;
}